﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using WpfApp.ReturnOperation;
using WpfApp.Controls;

namespace WpfApp
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        /// <summary>
        /// 当前进程句柄
        /// </summary>
        //public IntPtr CurWindows { get; set; }

        /// <summary>
        /// 主进程句柄
        /// </summary>
        public IntPtr ContainerPlayPtr { get; set; }

        public int UploadType { get; set; }

        public string CaseID { get; set; }

        #region 进程消息处理

        [DllImport("User32.dll", EntryPoint = "SendMessage")]
        private static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

        /// <summary>
        /// 向主窗体发送消息
        /// </summary>
        /// <param name="success">标识是否操作成功，可根据自己使用情况来定</param>
        private void Send(int success)
        {
            // 需要根据主窗体的句柄来发送，OperationContainer.ContainerPlayPtr在App程序初始化的时候已经取得的主窗体的句柄
            SendMessage(OperationContainer.ContainerPlayPtr, Message.WM_MSG, success, 0);
        }

        #endregion

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //MsgForm form = new MsgForm();
            //CurWindows = form.Handle;
            //ContainerPlayPtr = OperationContainer.ContainerPlayPtr;
            //MessageBox.Show("容器窗体句柄：" + ContainerPlayPtr.ToInt32());
            // 取得参数
            UploadType = Convert.ToInt32(OperationContainer.Type);
            CaseID = OperationContainer.CaseID;
        }

        private void btn_Upload(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(CaseID);
            // 向主窗体发送消息
            Send(0);
        }
    }
}
